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_
|
|
|
|
|
|
|
|
#include "WebGLObjectModel.h"
|
|
|
|
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
|
|
|
#include "mozilla/LinkedList.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
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
|
2012-12-09 03:58:41 -08:00
|
|
|
, public WebGLRefCountedObject<WebGLFramebuffer>
|
|
|
|
, public LinkedListElement<WebGLFramebuffer>
|
|
|
|
, public WebGLContextBoundObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebGLFramebuffer(WebGLContext *context);
|
|
|
|
|
|
|
|
~WebGLFramebuffer() {
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
|
|
|
|
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;
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum mAttachmentPoint;
|
|
|
|
GLint mTextureLevel;
|
2013-10-01 17:30:05 -07:00
|
|
|
GLenum mTextureTarget;
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum mTextureCubeMapFace;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
Attachment(GLenum aAttachmentPoint = LOCAL_GL_COLOR_ATTACHMENT0)
|
2012-12-09 03:58:41 -08:00
|
|
|
: mAttachmentPoint(aAttachmentPoint)
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool IsDefined() const {
|
|
|
|
return Texture() || Renderbuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDeleteRequested() const;
|
|
|
|
|
|
|
|
bool HasAlpha() const;
|
|
|
|
|
2013-10-01 17:30:05 -07:00
|
|
|
void SetTexture(WebGLTexture *tex, GLenum target, GLint level, GLenum face);
|
2012-12-09 03:58:41 -08:00
|
|
|
void SetRenderbuffer(WebGLRenderbuffer *rb) {
|
|
|
|
mTexturePtr = nullptr;
|
|
|
|
mRenderbufferPtr = rb;
|
|
|
|
}
|
|
|
|
const WebGLTexture *Texture() const {
|
|
|
|
return mTexturePtr;
|
|
|
|
}
|
|
|
|
WebGLTexture *Texture() {
|
|
|
|
return mTexturePtr;
|
|
|
|
}
|
|
|
|
const WebGLRenderbuffer *Renderbuffer() const {
|
|
|
|
return mRenderbufferPtr;
|
|
|
|
}
|
|
|
|
WebGLRenderbuffer *Renderbuffer() {
|
|
|
|
return mRenderbufferPtr;
|
|
|
|
}
|
2013-10-01 17:30:05 -07:00
|
|
|
GLenum TextureTarget() const {
|
|
|
|
return mTextureTarget;
|
|
|
|
}
|
2013-09-04 05:14:43 -07:00
|
|
|
GLint TextureLevel() const {
|
2012-12-09 03:58:41 -08:00
|
|
|
return mTextureLevel;
|
|
|
|
}
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum TextureCubeMapFace() const {
|
2012-12-09 03:58:41 -08:00
|
|
|
return mTextureCubeMapFace;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasUninitializedRenderbuffer() const;
|
|
|
|
|
|
|
|
void Reset() {
|
|
|
|
mTexturePtr = nullptr;
|
|
|
|
mRenderbufferPtr = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const WebGLRectangleObject* RectangleObject() const;
|
|
|
|
bool HasSameDimensionsAs(const Attachment& other) const;
|
|
|
|
|
|
|
|
bool IsComplete() const;
|
2013-10-01 17:30:05 -07:00
|
|
|
|
|
|
|
void FinalizeAttachment(GLenum attachmentLoc) const;
|
2012-12-09 03:58:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
void Delete();
|
|
|
|
|
|
|
|
bool HasEverBeenBound() { return mHasEverBeenBound; }
|
|
|
|
void SetHasEverBeenBound(bool x) { mHasEverBeenBound = x; }
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint GLName() { return mGLName; }
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void FramebufferRenderbuffer(GLenum target,
|
|
|
|
GLenum attachment,
|
|
|
|
GLenum rbtarget,
|
2012-12-09 03:58:41 -08:00
|
|
|
WebGLRenderbuffer *wrb);
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void FramebufferTexture2D(GLenum target,
|
|
|
|
GLenum attachment,
|
|
|
|
GLenum textarget,
|
2012-12-09 03:58:41 -08:00
|
|
|
WebGLTexture *wtex,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLint level);
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2013-06-21 16:44:17 -07:00
|
|
|
bool HasIncompleteAttachment() const;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
|
|
|
bool HasDepthStencilConflict() const {
|
|
|
|
return int(mDepthAttachment.IsDefined()) +
|
|
|
|
int(mStencilAttachment.IsDefined()) +
|
|
|
|
int(mDepthStencilAttachment.IsDefined()) >= 2;
|
|
|
|
}
|
|
|
|
|
2013-06-21 16:44:17 -07:00
|
|
|
bool HasAttachmentsOfMismatchedDimensions() const;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
2013-10-01 17:30:05 -07:00
|
|
|
const size_t ColorAttachmentCount() const {
|
|
|
|
return mColorAttachments.Length();
|
|
|
|
}
|
2013-06-21 16:44:17 -07:00
|
|
|
const Attachment& ColorAttachment(uint32_t colorAttachmentId) const {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
const Attachment& GetAttachment(GLenum attachment) const;
|
2012-12-09 03:58:41 -08:00
|
|
|
|
|
|
|
void DetachTexture(const WebGLTexture *tex);
|
|
|
|
|
|
|
|
void DetachRenderbuffer(const WebGLRenderbuffer *rb);
|
|
|
|
|
|
|
|
const WebGLRectangleObject *RectangleObject() {
|
2013-06-21 16:44:17 -07:00
|
|
|
return mColorAttachments[0].RectangleObject();
|
2012-12-09 03:58:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
WebGLContext *GetParentObject() const {
|
|
|
|
return Context();
|
|
|
|
}
|
|
|
|
|
2013-10-01 17:30:05 -07:00
|
|
|
void FinalizeAttachments() const;
|
|
|
|
|
2013-04-25 09:29:54 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx,
|
|
|
|
JS::Handle<JSObject*> scope) 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
|
|
|
|
|
|
|
bool CheckAndInitializeRenderbuffers();
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
bool CheckColorAttachementNumber(GLenum attachment, const char * functionName) const;
|
2013-06-21 16:44:17 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint mGLName;
|
2012-12-09 03:58:41 -08:00
|
|
|
bool mHasEverBeenBound;
|
|
|
|
|
2013-06-21 16:44:17 -07:00
|
|
|
void EnsureColorAttachments(size_t colorAttachmentId);
|
|
|
|
|
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
|