content/canvas/src/WebGLFramebuffer.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef WEBGLFRAMEBUFFER_H_
michael@0 7 #define WEBGLFRAMEBUFFER_H_
michael@0 8
michael@0 9 #include "WebGLObjectModel.h"
michael@0 10
michael@0 11 #include "nsWrapperCache.h"
michael@0 12
michael@0 13 #include "mozilla/LinkedList.h"
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16
michael@0 17 class WebGLFramebufferAttachable;
michael@0 18 class WebGLTexture;
michael@0 19 class WebGLRenderbuffer;
michael@0 20 namespace gl {
michael@0 21 class GLContext;
michael@0 22 }
michael@0 23
michael@0 24 class WebGLFramebuffer MOZ_FINAL
michael@0 25 : public nsWrapperCache
michael@0 26 , public WebGLRefCountedObject<WebGLFramebuffer>
michael@0 27 , public LinkedListElement<WebGLFramebuffer>
michael@0 28 , public WebGLContextBoundObject
michael@0 29 {
michael@0 30 public:
michael@0 31 WebGLFramebuffer(WebGLContext* context);
michael@0 32
michael@0 33 ~WebGLFramebuffer() {
michael@0 34 DeleteOnce();
michael@0 35 }
michael@0 36
michael@0 37 struct Attachment
michael@0 38 {
michael@0 39 // deleting a texture or renderbuffer immediately detaches it
michael@0 40 WebGLRefPtr<WebGLTexture> mTexturePtr;
michael@0 41 WebGLRefPtr<WebGLRenderbuffer> mRenderbufferPtr;
michael@0 42 GLenum mAttachmentPoint;
michael@0 43 GLenum mTexImageTarget;
michael@0 44 GLint mTexImageLevel;
michael@0 45 mutable bool mNeedsFinalize;
michael@0 46
michael@0 47 Attachment(GLenum aAttachmentPoint = LOCAL_GL_COLOR_ATTACHMENT0)
michael@0 48 : mAttachmentPoint(aAttachmentPoint)
michael@0 49 , mNeedsFinalize(false)
michael@0 50 {}
michael@0 51
michael@0 52 bool IsDefined() const {
michael@0 53 return Texture() || Renderbuffer();
michael@0 54 }
michael@0 55
michael@0 56 bool IsDeleteRequested() const;
michael@0 57
michael@0 58 bool HasAlpha() const;
michael@0 59 bool IsReadableFloat() const;
michael@0 60
michael@0 61 void SetTexImage(WebGLTexture* tex, GLenum target, GLint level);
michael@0 62 void SetRenderbuffer(WebGLRenderbuffer* rb);
michael@0 63
michael@0 64 const WebGLTexture* Texture() const {
michael@0 65 return mTexturePtr;
michael@0 66 }
michael@0 67 WebGLTexture* Texture() {
michael@0 68 return mTexturePtr;
michael@0 69 }
michael@0 70 const WebGLRenderbuffer* Renderbuffer() const {
michael@0 71 return mRenderbufferPtr;
michael@0 72 }
michael@0 73 WebGLRenderbuffer* Renderbuffer() {
michael@0 74 return mRenderbufferPtr;
michael@0 75 }
michael@0 76 GLenum TexImageTarget() const {
michael@0 77 return mTexImageTarget;
michael@0 78 }
michael@0 79 GLint TexImageLevel() const {
michael@0 80 return mTexImageLevel;
michael@0 81 }
michael@0 82
michael@0 83 bool HasUninitializedImageData() const;
michael@0 84 void SetImageDataStatus(WebGLImageDataStatus x);
michael@0 85
michael@0 86 void Reset() {
michael@0 87 mTexturePtr = nullptr;
michael@0 88 mRenderbufferPtr = nullptr;
michael@0 89 }
michael@0 90
michael@0 91 const WebGLRectangleObject& RectangleObject() const;
michael@0 92
michael@0 93 bool HasImage() const;
michael@0 94 bool IsComplete() const;
michael@0 95
michael@0 96 void FinalizeAttachment(gl::GLContext* gl, GLenum attachmentLoc) const;
michael@0 97 };
michael@0 98
michael@0 99 void Delete();
michael@0 100
michael@0 101 bool HasEverBeenBound() { return mHasEverBeenBound; }
michael@0 102 void SetHasEverBeenBound(bool x) { mHasEverBeenBound = x; }
michael@0 103 GLuint GLName() { return mGLName; }
michael@0 104
michael@0 105 void FramebufferRenderbuffer(GLenum target,
michael@0 106 GLenum attachment,
michael@0 107 GLenum rbtarget,
michael@0 108 WebGLRenderbuffer* wrb);
michael@0 109
michael@0 110 void FramebufferTexture2D(GLenum target,
michael@0 111 GLenum attachment,
michael@0 112 GLenum textarget,
michael@0 113 WebGLTexture* wtex,
michael@0 114 GLint level);
michael@0 115
michael@0 116 private:
michael@0 117 void DetachAttachment(WebGLFramebuffer::Attachment& attachment);
michael@0 118 void DetachAllAttachments();
michael@0 119 const WebGLRectangleObject& GetAnyRectObject() const;
michael@0 120 Attachment* GetAttachmentOrNull(GLenum attachment);
michael@0 121
michael@0 122 public:
michael@0 123 bool HasDefinedAttachments() const;
michael@0 124 bool HasIncompleteAttachments() const;
michael@0 125 bool AllImageRectsMatch() const;
michael@0 126 GLenum PrecheckFramebufferStatus() const;
michael@0 127 GLenum CheckFramebufferStatus() const;
michael@0 128
michael@0 129 bool HasDepthStencilConflict() const {
michael@0 130 return int(mDepthAttachment.IsDefined()) +
michael@0 131 int(mStencilAttachment.IsDefined()) +
michael@0 132 int(mDepthStencilAttachment.IsDefined()) >= 2;
michael@0 133 }
michael@0 134
michael@0 135 size_t ColorAttachmentCount() const {
michael@0 136 return mColorAttachments.Length();
michael@0 137 }
michael@0 138 const Attachment& ColorAttachment(size_t colorAttachmentId) const {
michael@0 139 return mColorAttachments[colorAttachmentId];
michael@0 140 }
michael@0 141
michael@0 142 const Attachment& DepthAttachment() const {
michael@0 143 return mDepthAttachment;
michael@0 144 }
michael@0 145
michael@0 146 const Attachment& StencilAttachment() const {
michael@0 147 return mStencilAttachment;
michael@0 148 }
michael@0 149
michael@0 150 const Attachment& DepthStencilAttachment() const {
michael@0 151 return mDepthStencilAttachment;
michael@0 152 }
michael@0 153
michael@0 154 const Attachment& GetAttachment(GLenum attachment) const;
michael@0 155
michael@0 156 void DetachTexture(const WebGLTexture* tex);
michael@0 157
michael@0 158 void DetachRenderbuffer(const WebGLRenderbuffer* rb);
michael@0 159
michael@0 160 const WebGLRectangleObject& RectangleObject() const;
michael@0 161
michael@0 162 WebGLContext* GetParentObject() const {
michael@0 163 return Context();
michael@0 164 }
michael@0 165
michael@0 166 void FinalizeAttachments() const;
michael@0 167
michael@0 168 virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE;
michael@0 169
michael@0 170 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLFramebuffer)
michael@0 171 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLFramebuffer)
michael@0 172
michael@0 173 // mask mirrors glClear.
michael@0 174 bool HasCompletePlanes(GLbitfield mask);
michael@0 175
michael@0 176 bool CheckAndInitializeAttachments();
michael@0 177
michael@0 178 bool CheckColorAttachmentNumber(GLenum attachment, const char* functionName) const;
michael@0 179
michael@0 180 void EnsureColorAttachments(size_t colorAttachmentId);
michael@0 181
michael@0 182 Attachment* AttachmentFor(GLenum attachment);
michael@0 183 void NotifyAttachableChanged() const;
michael@0 184
michael@0 185 private:
michael@0 186 mutable GLenum mStatus;
michael@0 187
michael@0 188 GLuint mGLName;
michael@0 189 bool mHasEverBeenBound;
michael@0 190
michael@0 191 // we only store pointers to attached renderbuffers, not to attached textures, because
michael@0 192 // we will only need to initialize renderbuffers. Textures are already initialized.
michael@0 193 nsTArray<Attachment> mColorAttachments;
michael@0 194 Attachment mDepthAttachment,
michael@0 195 mStencilAttachment,
michael@0 196 mDepthStencilAttachment;
michael@0 197 };
michael@0 198
michael@0 199 } // namespace mozilla
michael@0 200
michael@0 201 #endif

mercurial