2012-12-09 03:58:41 -08: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/. */
|
|
|
|
|
|
|
|
#ifndef WEBGLFRAMEBUFFER_H_
|
|
|
|
#define WEBGLFRAMEBUFFER_H_
|
|
|
|
|
2014-05-06 20:11:18 -07:00
|
|
|
#include "WebGLBindableName.h"
|
2012-12-09 03:58:41 -08:00
|
|
|
#include "WebGLObjectModel.h"
|
2014-09-18 16:14:22 -07:00
|
|
|
#include "WebGLStrongTypes.h"
|
2012-12-09 03:58:41 -08:00
|
|
|
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
|
|
|
#include "mozilla/LinkedList.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-03-03 23:14:35 -08:00
|
|
|
class WebGLFramebufferAttachable;
|
2012-12-09 03:58:41 -08:00
|
|
|
class WebGLTexture;
|
|
|
|
class WebGLRenderbuffer;
|
2013-10-01 17:30:05 -07:00
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
|
|
|
}
|
2012-12-09 03:58:41 -08:00
|
|
|
|
|
|
|
class WebGLFramebuffer MOZ_FINAL
|
2013-08-29 08:39:17 -07:00
|
|
|
: public nsWrapperCache
|
2014-09-25 08:21:33 -07:00
|
|
|
, public WebGLBindableName<FBTarget>
|
2012-12-09 03:58:41 -08:00
|
|
|
, public WebGLRefCountedObject<WebGLFramebuffer>
|
|
|
|
, public LinkedListElement<WebGLFramebuffer>
|
|
|
|
, public WebGLContextBoundObject
|
2014-07-30 12:52:07 -07:00
|
|
|
, public SupportsWeakPtr<WebGLFramebuffer>
|
2012-12-09 03:58:41 -08:00
|
|
|
{
|
|
|
|
public:
|
2014-07-30 12:52:07 -07:00
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(WebGLFramebuffer)
|
|
|
|
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit WebGLFramebuffer(WebGLContext* context);
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2013-06-21 16:44:17 -07:00
|
|
|
struct Attachment
|
2012-12-09 03:58:41 -08:00
|
|
|
{
|
|
|
|
// deleting a texture or renderbuffer immediately detaches it
|
|
|
|
WebGLRefPtr<WebGLTexture> mTexturePtr;
|
|
|
|
WebGLRefPtr<WebGLRenderbuffer> mRenderbufferPtr;
|
2014-09-25 08:21:33 -07:00
|
|
|
FBAttachment mAttachmentPoint;
|
2014-09-18 16:14:22 -07:00
|
|
|
TexImageTarget mTexImageTarget;
|
2013-10-01 17:30:38 -07:00
|
|
|
GLint mTexImageLevel;
|
2014-03-11 16:10:59 -07:00
|
|
|
mutable bool mNeedsFinalize;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-09-25 08:21:33 -07:00
|
|
|
explicit Attachment(FBAttachment aAttachmentPoint = LOCAL_GL_COLOR_ATTACHMENT0);
|
2014-07-30 12:52:07 -07:00
|
|
|
~Attachment();
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-09-23 10:48:27 -07:00
|
|
|
bool IsDefined() const;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
|
|
|
bool IsDeleteRequested() const;
|
2014-10-07 16:52:58 -07:00
|
|
|
|
|
|
|
TexInternalFormat EffectiveInternalFormat() const;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
|
|
|
bool HasAlpha() const;
|
2014-07-21 08:17:00 -07:00
|
|
|
bool IsReadableFloat() const;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-09-18 16:14:22 -07:00
|
|
|
void SetTexImage(WebGLTexture* tex, TexImageTarget target, GLint level);
|
2014-03-11 16:10:59 -07:00
|
|
|
void SetRenderbuffer(WebGLRenderbuffer* rb);
|
|
|
|
|
2014-01-22 19:59:34 -08:00
|
|
|
const WebGLTexture* Texture() const {
|
2012-12-09 03:58:41 -08:00
|
|
|
return mTexturePtr;
|
|
|
|
}
|
2014-01-22 19:59:34 -08:00
|
|
|
WebGLTexture* Texture() {
|
2012-12-09 03:58:41 -08:00
|
|
|
return mTexturePtr;
|
|
|
|
}
|
2014-01-22 19:59:34 -08:00
|
|
|
const WebGLRenderbuffer* Renderbuffer() const {
|
2012-12-09 03:58:41 -08:00
|
|
|
return mRenderbufferPtr;
|
|
|
|
}
|
2014-01-22 19:59:34 -08:00
|
|
|
WebGLRenderbuffer* Renderbuffer() {
|
2012-12-09 03:58:41 -08:00
|
|
|
return mRenderbufferPtr;
|
|
|
|
}
|
2014-09-18 16:14:22 -07:00
|
|
|
TexImageTarget ImageTarget() const {
|
2013-10-01 17:30:38 -07:00
|
|
|
return mTexImageTarget;
|
2013-10-01 17:30:05 -07:00
|
|
|
}
|
2014-09-18 16:14:22 -07:00
|
|
|
GLint MipLevel() const {
|
2013-10-01 17:30:38 -07:00
|
|
|
return mTexImageLevel;
|
2012-12-09 03:58:41 -08:00
|
|
|
}
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
bool HasUninitializedImageData() const;
|
|
|
|
void SetImageDataStatus(WebGLImageDataStatus x);
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-07-30 12:52:07 -07:00
|
|
|
void Reset();
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-01-22 19:59:34 -08:00
|
|
|
const WebGLRectangleObject& RectangleObject() const;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-01-22 19:59:34 -08:00
|
|
|
bool HasImage() const;
|
2012-12-09 03:58:41 -08:00
|
|
|
bool IsComplete() const;
|
2013-10-01 17:30:05 -07:00
|
|
|
|
2014-09-25 08:21:33 -07:00
|
|
|
void FinalizeAttachment(gl::GLContext* gl, FBAttachment attachmentLoc) const;
|
2012-12-09 03:58:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
void Delete();
|
|
|
|
|
2014-09-25 08:21:33 -07:00
|
|
|
void FramebufferRenderbuffer(FBAttachment attachment,
|
|
|
|
RBTarget rbtarget,
|
2014-01-22 19:59:34 -08:00
|
|
|
WebGLRenderbuffer* wrb);
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-09-25 08:21:33 -07:00
|
|
|
void FramebufferTexture2D(FBAttachment attachment,
|
2014-09-18 16:14:22 -07:00
|
|
|
TexImageTarget texImageTarget,
|
2014-01-22 19:59:34 -08:00
|
|
|
WebGLTexture* wtex,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLint level);
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-01-22 19:59:34 -08:00
|
|
|
private:
|
2014-06-24 00:15:44 -07:00
|
|
|
void DetachAttachment(WebGLFramebuffer::Attachment& attachment);
|
|
|
|
void DetachAllAttachments();
|
2014-01-22 19:59:34 -08:00
|
|
|
const WebGLRectangleObject& GetAnyRectObject() const;
|
2014-09-25 08:21:33 -07:00
|
|
|
Attachment* GetAttachmentOrNull(FBAttachment attachment);
|
2014-01-22 19:59:34 -08:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool HasDefinedAttachments() const;
|
|
|
|
bool HasIncompleteAttachments() const;
|
|
|
|
bool AllImageRectsMatch() const;
|
2014-09-25 08:21:33 -07:00
|
|
|
FBStatus PrecheckFramebufferStatus() const;
|
|
|
|
FBStatus CheckFramebufferStatus() const;
|
2014-08-20 13:38:42 -07:00
|
|
|
GLenum GetFormatForAttachment(const WebGLFramebuffer::Attachment& attachment) const;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
|
|
|
bool HasDepthStencilConflict() const {
|
|
|
|
return int(mDepthAttachment.IsDefined()) +
|
|
|
|
int(mStencilAttachment.IsDefined()) +
|
|
|
|
int(mDepthStencilAttachment.IsDefined()) >= 2;
|
|
|
|
}
|
|
|
|
|
2014-01-22 19:59:34 -08:00
|
|
|
size_t ColorAttachmentCount() const {
|
2013-10-01 17:30:05 -07:00
|
|
|
return mColorAttachments.Length();
|
|
|
|
}
|
2014-01-22 19:59:34 -08:00
|
|
|
const Attachment& ColorAttachment(size_t colorAttachmentId) const {
|
2013-06-21 16:44:17 -07:00
|
|
|
return mColorAttachments[colorAttachmentId];
|
2012-12-09 03:58:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Attachment& DepthAttachment() const {
|
|
|
|
return mDepthAttachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Attachment& StencilAttachment() const {
|
|
|
|
return mStencilAttachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Attachment& DepthStencilAttachment() const {
|
|
|
|
return mDepthStencilAttachment;
|
|
|
|
}
|
|
|
|
|
2014-09-25 08:21:33 -07:00
|
|
|
const Attachment& GetAttachment(FBAttachment attachment) const;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-01-22 19:59:34 -08:00
|
|
|
void DetachTexture(const WebGLTexture* tex);
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-01-22 19:59:34 -08:00
|
|
|
void DetachRenderbuffer(const WebGLRenderbuffer* rb);
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-01-22 19:59:34 -08:00
|
|
|
const WebGLRectangleObject& RectangleObject() const;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-01-22 19:59:34 -08:00
|
|
|
WebGLContext* GetParentObject() const {
|
2012-12-09 03:58:41 -08:00
|
|
|
return Context();
|
|
|
|
}
|
|
|
|
|
2013-10-01 17:30:05 -07:00
|
|
|
void FinalizeAttachments() const;
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2013-08-29 08:39:17 -07:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLFramebuffer)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLFramebuffer)
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-02-28 18:51:43 -08:00
|
|
|
// mask mirrors glClear.
|
|
|
|
bool HasCompletePlanes(GLbitfield mask);
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
bool CheckAndInitializeAttachments();
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2014-09-25 08:21:33 -07:00
|
|
|
bool CheckColorAttachmentNumber(FBAttachment attachment, const char* functionName) const;
|
2013-06-21 16:44:17 -07:00
|
|
|
|
2014-03-03 23:14:35 -08:00
|
|
|
void EnsureColorAttachments(size_t colorAttachmentId);
|
|
|
|
|
|
|
|
void NotifyAttachableChanged() const;
|
|
|
|
|
|
|
|
private:
|
2014-06-26 06:30:49 -07:00
|
|
|
~WebGLFramebuffer() {
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
|
|
|
|
2014-03-03 23:14:35 -08:00
|
|
|
mutable GLenum mStatus;
|
|
|
|
|
2012-12-09 03:58:41 -08:00
|
|
|
// we only store pointers to attached renderbuffers, not to attached textures, because
|
|
|
|
// we will only need to initialize renderbuffers. Textures are already initialized.
|
2013-06-21 16:44:17 -07:00
|
|
|
nsTArray<Attachment> mColorAttachments;
|
|
|
|
Attachment mDepthAttachment,
|
2012-12-09 03:58:41 -08:00
|
|
|
mStencilAttachment,
|
|
|
|
mDepthStencilAttachment;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|